# Create your views here.
from django.shortcuts import render,HttpResponse,render_to_response,redirect
from blog.models import *
from blog.sql import sqlexecute
# from practice.day54_mysql.python_mysql import sqlexecute


class myclass():
    def __init__(self,name,age,sex):
        self.name=name
        self.age=age
        self.sex=sex

def showtime(request):
    import time,datetime
    t=time.ctime()
    name='BOB'
    test ='h e l lo w o rl d'
    L0 = []
    L=[2,5,6,7,4,2,9]
    tt =datetime.datetime.now()
    L=['张三','李四','赵武','钱六']
    people = myclass('古力娜扎',26,'女')
    dic={"name":"鞠婧祎","sex":"女","age":"24"}
    d={"name":"鞠婧祎","sex":"女","age":24}
    # return HttpResponse(date)
    a="<a href=''> click</a>"
    # return render(request,"index.html",{"time":t,'name':name})
    return render(request,"index.html",locals())

def articleYear(request,year):

    return HttpResponse(year)

def articleYearMonth(request,year,month):

    return HttpResponse('%s-%s'%(year,month))

def registe(request):
    print(request.path)
    print('--------------')
    print(request.get_full_path)
    if request.method=='POST':
        print(request.POST.get('user'))
        print(request.POST.getlist('hobby'))
        user=request.POST.get('user')
        if user=='BOB':
            return redirect('/blog/login/')

        return HttpResponse('SUCCESS')
    return render(request,'registe.html')

def login(request):
    name='BOB'
    return render(request,"login.html",locals())


def denglu(request):

    return HttpResponse('OK')


def home(request):

    return render(request,'base.html')


def student(request):

    studentList = ['阿明','萌萌','汪涵','李丹','鞠婧祎','白娘子','许仙']

    return render(request,'student.html',locals())



#
# def book(request):
#
#     return render(request,'book.html')
#
# def select(request):
#     # bookList=Book.objects.all()[:1]
#     # bookList=Book.objects.get(id=1) # get 只能取出一个的情况才不会出错
#     # bookList=Book.objects.all()[::2]
#     # 取出作者是追风的书的名字  values() 那某一个字段名
#     # bookList=Book.objects.filter(author='追风').values("title",'author')
#     str = '追风'
#     bookList = sqlexecute("select * from blog_book WHERE author='追风'")
#     print("--->" ,type(bookList))
#     print(bookList)
#     # bookList=Book.objects.raw("select title,author from blog_book WHERE author='追风'")
#     return render(request,'book.html',locals())
#
#
# def addbook(request):
#     Book.objects.create(title='django框架',publishDate='2017-12-12',author='追风',price=89)
#     b=Book(title='Linux',publishDate='2017-12-12',author='追风赤子',price=99)
#     b.save()
#     return HttpResponse("添加成功")
#
#
# def update(request):
#     Book.objects.filter(author='追风赤子').update(price=68)
#     Book.objects.filter(title='django框架').update(publishDate='2010-06-09')
#     Book.objects,filter(id=4).update(title='骆驼祥子')
#     return HttpResponse('修改成功')
#
# def delete(request):
#
#     Book.objects.filter(title='Linux').delete()
#
#     return HttpResponse('删除成功')


